<?php
	header("Content-Type: text/html;charset=utf-8");
	include("../_judge.php");
	include("../../function/function.php");
	
	$action = chkstr(trim($_REQUEST['action']));
	$news_language = chkstr(trim($_REQUEST['news_language']));
	$news_title = chkstr(trim($_REQUEST['news_title']));
	$news_bigclass = chkstr(trim($_REQUEST['news_bigclass']));
	$news_pic = chkstr(trim($_REQUEST['news_pic']));
	$news_tourls = chkstr(trim($_REQUEST['news_tourls']));
	$news_order = $_REQUEST['news_order'];
	$news_text = chkstr(trim($_REQUEST['news_text']));
	$news_starttime = chkstr(trim($_REQUEST['news_starttime']));
	$news_endtime = chkstr(trim($_REQUEST['news_endtime']));
	$now_time = date("Y-m-d H:i:s");
	$re_url = trim($_REQUEST['re_url']);
	$newsid = $_REQUEST['newsid'];
	$news_option = chkstr(trim($_REQUEST['news_option']));
	$id = trim($_REQUEST['id']);
	
	if(is_array($newsid)){ // 拆分数组
		$newsid = implode(',',$newsid);
	}

	if($action == "add"){
		if(strlen($news_title)<1 || strlen($news_bigclass)<1){
			echo erro("请将信息填写完整");
		}
		
		// 添加数据
		$mysql = new sqlstr("kboy_piclink"); 
		$mysql -> set("news_language",$news_language,true);
		$mysql -> set("news_title",$news_title);
		$mysql -> set("news_bigclass",$news_bigclass,true);
		$mysql -> set("news_pic",$news_pic);
		$mysql -> set("news_tourls",$news_tourls);
		$mysql -> set("news_text",$news_text);
		$mysql -> set("news_starttime",$news_starttime);
		$mysql -> set("news_endtime",$news_endtime);
		$news_sql = $mysql -> insertSql();
		$news_res = mysql_query($news_sql);
		if($news_res){
			$get_id = mysql_insert_id(); //获取最后一条插入的id
			mysql_query("update kboy_piclink set news_order=$get_id where id=$get_id");
			echo ok("操作成功","newsadd.php");
		}else{
			echo erro("服务器内部错误");
		}

	}elseif($action == "edit"){
		if(strlen($news_title)<1 || strlen($news_bigclass)<1 || strlen($id)<1){
			echo erro("请将信息填写完整");
		}
		if(!is_numeric($id)){
			echo erro("ID错误");
		}

		// 修改数据
		$mysql = new sqlstr("kboy_piclink"); 
		$mysql -> set("news_language",$news_language,true);
		$mysql -> set("news_title",$news_title);
		$mysql -> set("news_bigclass",$news_bigclass,true);
		$mysql -> set("news_pic",$news_pic);
		$mysql -> set("news_tourls",$news_tourls);
		$mysql -> set("news_text",$news_text);
		$mysql -> set("news_starttime",$news_starttime);
		$mysql -> set("news_endtime",$news_endtime);
		$news_sql = $mysql -> updateSql("id=$id");
		$news_res = mysql_query($news_sql);
		if($news_res){
			echo ok("操作成功",$re_url);
		}else{
			echo erro("服务器内部错误");
		}
		
	}elseif($action == "del"){
		if($news_option == "del"){
			if(!empty($newsid)){
				// 删除数据
				$mysql = new sqlstr("kboy_piclink"); 
				$news_sql = $mysql -> deleteSql("id in($newsid)");
				$news_res = mysql_query($news_sql);
				if($news_res){
					echo ok("操作成功",$_SERVER['HTTP_REFERER']);
				}else{
					echo erro("服务器内部错误");
				}
			}else{
				echo erro("至少选择一条记录进行操作");
			}
		}else{
			erro("请选择要操作的方式");
		}
	
	}elseif($action == "ztop"){//广告置顶
		if(strlen($id)<1){
			echo erro("ID错误");
		}
		if(!is_numeric($id)){
			echo erro("ID错误");
		}
		
		$mysql = new sqlstr("kboy_piclink"); 
		$mysql -> set("news_top",$now_time);
		$news_sql = $mysql -> updateSql("id=$id");
		$news_res = mysql_query($news_sql);
		if($news_res){
			echo re($_SERVER['HTTP_REFERER']);
		}else{
			echo erro("服务器内部错误");
		}
		
	}elseif($action == "ntop"){//取消广告置顶
		if(strlen($id)<1){
			echo erro("ID错误");
		}
		if(!is_numeric($id)){
			echo erro("ID错误");
		}
		$mysql = new sqlstr("kboy_piclink"); 
		$mysql -> set("news_top","");
		$news_sql = $mysql -> updateSql("id=$id");
		$news_res = mysql_query($news_sql);
		if($news_res){
			echo re($_SERVER['HTTP_REFERER']);
		}else{
			echo erro("服务器内部错误");
		}
		
	}elseif($action == "ordernum"){//取消广告置顶
		if(strlen($id)<1){
			echo erro("ID错误");
		}
		if(!is_numeric($id)){
			echo erro("ID错误");
		}
		if(!is_numeric($news_order)){
			echo erro("顺位错误");
		}
		if($news_order<=0){
			echo erro("顺位错误");
		}
		$mysql = new sqlstr("kboy_piclink"); 
		$mysql -> set("news_order",$news_order);
		$news_sql = $mysql -> updateSql("id=$id");
		$news_res = mysql_query($news_sql);
		if($news_res){
			echo re($_SERVER['HTTP_REFERER']);
		}else{
			echo erro("服务器内部错误");
		}
		
	}else{
		echo erro("参数错误");
	}
	
?>
